package com.nulldev.util.web.HttpServer3;

import com.nulldev.util.JVM.Arguments;
import com.nulldev.util.io.IOUtils;

public enum CopyAcceleration {
	/**
	 * No acceleration is used, just a simple copy loop.
	 */
	DISABLED,
	/**
	 * IOUtils' copy() is used, using NIO to accelerate buffer copying.
	 */
	FAST_COPY,
	/**
	 * Same as <code>DISABLED</code>, but using the transferTo() method introduced
	 * in Java 9.
	 */
	J9_COPY,

	;

	public static CopyAcceleration get() {
		if (Arguments.hasArgument("--CopyAcceleration.useJ9Copy")) {
			return J9_COPY;
		} else if (Arguments.hasArgument("--CopyAcceleration.fastCopy")) {
			return FAST_COPY;
		} else if (Arguments.hasArgument("--CopyAcceleration.disabled")) {
			return DISABLED;
		} else {
			return (IOUtils.canUseFastCopy() ? FAST_COPY : J9_COPY);
		}
	}
}
